from sentence_cut.PredfixDict import get_prefix_dict
def get_DAG(sentence, freq):
    DAG = {}
    N = len(sentence)
    for k in range(N):
        tmplist = []
        i = k
        frag = sentence[k]
        while i < N and frag in freq:
            if freq[frag]:
                tmplist.append(i)
            i += 1
            frag = sentence[k:i + 1]
        if not tmplist:
            tmplist.append(k)
        DAG[k] = tmplist
    return DAG

if __name__=="__main__":
    example = "我在学习结巴分词"
    freq, total = get_prefix_dict("./dict.txt")
    dag = get_DAG(example, freq)
    print(dag)
    {0: [0], 1: [1], 2: [2, 3], 3: [3], 4: [4, 5, 7], 5: [5], 6: [6, 7], 7: [7]}